package com.sx.core.vo;



import com.alibaba.fastjson.JSON;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

public class JsonReaderResponse implements Serializable {
    public Collection data = new ArrayList();
    public String message = "";
    public Boolean success = Boolean.TRUE;
    public long total = 0;
    public int page = 1;
    public int limit = 10;
    public int code = 0;
    public int start = 0;
    public Object extra;

    public JsonReaderResponse() {

    }

    public JsonReaderResponse(Collection data, long total, int page, int limit) {
        this.total = total;
        this.data = data;
        this.page = page;
        this.limit = limit;
    }


    public JsonReaderResponse(Collection data) {
        this.data = data;
        this.total = (data != null ? data.size() : total);
    }
    public JsonReaderResponse(Collection data,long total) {
        this.data = data;
        this.total = total;
    }


    public JsonReaderResponse(String message, int code) {
        this.data = Collections.EMPTY_LIST;
        this.message = message;
        this.code = code;
        this.success = Boolean.FALSE;
    }

    public Collection getData() {
        return data;
    }

    public JsonReaderResponse setData(Collection data) {
        this.data.clear();
        this.data.addAll(data);
        return this;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public long getTotal() {
        return total;
    }

    public JsonReaderResponse setTotal(long total) {
        this.total = total;
        return this;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String toJson() {
        return JSON.toJSONString(this);
    }

    public JsonReaderResponse addData(Object o) {
        this.data.add(o);
        return this;
    }

    public JsonReaderResponse data(Object o) {
        this.extra = o;
        return this;
    }

    public JsonReaderResponse addExtra(Object o) {
        this.extra = o;
        return this;
    }

    public Object getExtra() {
        return extra;
    }

    public void setExtra(Object extra) {
        this.extra = extra;
    }

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }
}
